//
// Created by zxh on 2019-12-19.
//

#ifndef MY_APPLICATION_USB_HOTPLUG_CHECK_H
#define MY_APPLICATION_USB_HOTPLUG_CHECK_H

#include "common.h"

#define UEVENT_BUFFER_SIZE 2048
#define USB_SERIAL_AMOUNT 0X08

/*
rk3399 串口1 
add@/devices/platform/fe3a0000.usb/usb6/6-1
add@/devices/platform/fe3a0000.usb/usb6/6-1/6-1:1.0
add@/devices/platform/fe3a0000.usb/usb6/6-1/6-1:1.0/ttyUSB5
add@/devices/platform/fe3a0000.usb/usb6/6-1/6-1:1.0/ttyUSB5/tty/ttyUSB5

remove@/devices/platform/fe3a0000.usb/usb6/6-1/6-1:1.0/ttyUSB5/tty/ttyUSB5
remove@/devices/platform/fe3a0000.usb/usb6/6-1/6-1:1.0/ttyUSB5
remove@/devices/platform/fe3a0000.usb/usb6/6-1/6-1:1.0
remove@/devices/platform/fe3a0000.usb/usb6/6-1

rk3399 串口2 
add@/devices/platform/fe3e0000.usb/usb2/2-1
add@/devices/platform/fe3e0000.usb/usb2/2-1/2-1:1.0
add@/devices/platform/fe3e0000.usb/usb2/2-1/2-1:1.0/ttyUSB1
add@/devices/platform/fe3e0000.usb/usb2/2-1/2-1:1.0/ttyUSB1/tty/ttyUSB1

remove@/devices/platform/fe3e0000.usb/usb2/2-1/2-1:1.0/ttyUSB1/tty/ttyUSB1
remove@/devices/platform/fe3e0000.usb/usb2/2-1/2-1:1.0/ttyUSB1
remove@/devices/platform/fe3e0000.usb/usb2/2-1/2-1:1.0
remove@/devices/platform/fe3e0000.usb/usb2/2-1

*/

/*2.0  串口插入 提示符 */
#define HI3798_USB_SERIAL_2_0_INSERT_PROMPT "add@/devices/platform/hiusb-ohci.0/usb3/3-1/3-1:1.0/ttyUSB"

/*2.0  串口拔出 提示符 */
#define HI3798_USB_SERIAL_2_0_DELETE_PROMPT "remove@/devices/platform/hiusb-ohci.0/usb3/3-1/3-1:1.0/ttyUSB"

/*3.0  串口插入 提示符 */
#define HI3798_USB_SERIAL_3_0_INSERT_PROMPT "add@/devices/platform/hiusb-xhci.0/usb5/5-1/5-1:1.0/ttyUSB"

/*3.0  串口拔出 提示符 */
#define HI3798_USB_SERIAL_3_0_DELETE_PROMPT "remove@/devices/platform/hiusb-xhci.0/usb5/5-1/5-1:1.0/ttyUSB"

/*2.0  串口插入 提示符 */
#define RK3399_USB_SERIAL_2_0_1_INSERT_PROMPT "add@/devices/platform/fe3a0000.usb/usb6/6-1/6-1:1.0/ttyUSB"

/*2.0  串口拔出 提示符 */
#define RK3399_USB_SERIAL_2_0_1_DELETE_PROMPT "remove@/devices/platform/fe3a0000.usb/usb6/6-1/6-1:1.0/ttyUSB"

/*2.0  串口插入 提示符 */
#define RK3399_USB_SERIAL_2_0_2_INSERT_PROMPT "add@/devices/platform/fe3e0000.usb/usb2/2-1/2-1:1.0/ttyUSB"

/*2.0  串口拔出 提示符 */
#define RK3399_USB_SERIAL_2_0_2_DELETE_PROMPT "remove@/devices/platform/fe3e0000.usb/usb2/2-1/2-1:1.0/ttyUSB"

#define RK3399_USB_SERIAL_2_0_1_FILE_PATH "/devices/platform/fe3a0000.usb/usb6/6-1/6-1:1.0"
#define RK3399_USB_SERIAL_2_0_2_FILE_PATH "/devices/platform/fe3e0000.usb/usb2/2-1/2-1:1.0"
#define HI3798_USB_SERIAL_2_0_FILE_PATH	  "/devices/platform/hiusb-ohci.0/usb3/3-1/3-1:1.0"
#define HI3798_USB_SERIAL_3_0_FILE_PATH	  "/devices/platform/hiusb-xhci.0/usb5/5-1/5-1:1.0"

/*usb串口路径索引表 */
extern uint8_t UsbSerialDevicePathIndex[USB_SERIAL_AMOUNT][64];

typedef enum
{
    USB_SERIAL_N_INSERT = 0X00,
    USB_SERIAL_INSERT_OK = 0X01,
    USB_SERIAL_INIT_ERR = 0X02,
    USB_SERIAL_INIT_OK = 0X03,
}STRUCT_USB_SERIAL_STATUS;

/*USB 串口 状态检测*/
typedef struct
{
    uint32_t usbserialbautrate[USB_SERIAL_AMOUNT];      		/*串口波特率*/
	uint8_t usbseriachannellindex[USB_SERIAL_AMOUNT];          	/*串口索引*/
	uint8_t usbserialchannelenableflag[USB_SERIAL_AMOUNT];		/*串口使能标记 ： 0 ：串口没被启用 1 :串口被启用*/
	uint8_t usbserialcmdstruindex[USB_SERIAL_AMOUNT];			/*串口控制结构体索引*/
	uint8_t usbserialdevicepath[USB_SERIAL_AMOUNT][64];

	int usbserialfd[USB_SERIAL_AMOUNT];		/*打开的文件 fd*/		
    int usbserialhotplugstats;  /*usb串口热插拔状态 : 每两位代表一个usb设备的状态*/
    int usbserialinsertflag;	/*usb 串口设备插入 事件: 每两位代表一个usb设置的状态*/
}STRUCT_USB_SERIAL_HOTPLUG_DETECTION;

extern int hotplug_sock;
extern STRUCT_USB_SERIAL_HOTPLUG_DETECTION UsbSerialHotplugDetectionStru;

extern int init_hotplug_struct(uint8_t,uint32_t );
extern int init_hotplug_sock(void);
extern void * usb_device_hotplug_check_handle(void * arg);
extern int get_usb_serial_device_status(uint8_t );
extern int check_usb_serial_device_index(unsigned char * path);
extern int check_usable_usb_serial_channel(void);

#endif //MY_APPLICATION_USB_HOTPLUG_CHECK_H
